package com.isoft.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.isoft.dao.CheckChangedao;
import com.isoft.entity.AirportChange;
import com.isoft.entity.CheckChange;
import com.isoft.entity.PageBean;
import com.isoft.service.IAirportChangeService;
import com.isoft.service.ICheckChangeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;


@Service
public class CheckChangeService implements ICheckChangeService {
    @Autowired
    CheckChangedao checkChangedao;
    @Override
    public PageBean getAll(Integer page , Integer pageSize) {
        PageHelper.startPage(page, pageSize);
        List<CheckChange> airportChangeList = checkChangedao.getAll();
        Page<CheckChange> p = (Page<CheckChange>) airportChangeList;
        PageBean pageBean = new PageBean((int) p.getTotal(), p.getResult());
        return pageBean;
    }

    @Override
    public Boolean yetPermitYes(Integer id) {
        int i = checkChangedao.yetPermitYes(id);
        if(i>0){
            checkChangedao.addcheck(id);
            return true;
        }
        return false;
    }

    @Override
    public Boolean yetPermitNo(Integer id) {
        return checkChangedao.yetPermitNo(id)>0;
    }

    @Override
    public Boolean add(CheckChange checkChange) {
        checkChange.setIspermit(0);
        return checkChangedao.add(checkChange) > 0;
    }


}
